#include "mem.h"
#include "list.h"

list_t *list_create() {
    list_t *l = kmalloc(sizeof(list_t), 0);
    l->n.pre = &(l->n);
    l->n.next = &(l->n);
    l->size = 0;
    return l;
}

void list_add(list_t *l, void *d) {
    node_t *n = kmalloc(sizeof(node_t), 0);
    n->data = d;
    node_t *last = l->n.pre;
    last->next = n;
    n->pre = last;
    n->next = &(l->n);
    l->n.pre = n;
    l->size++;
}

void list_remove(list_t *l, node_t *n) {
    n->pre->next = n->next;
    n->next->pre = n->pre;
    l->size--;
}